package com.css.fxfzxczh.modules.samplingPointDataCensus.emergencystatistics.service.impl;

import com.css.fxfzxczh.modules.disasterSituationDataManage.emergencyReport.entity.EmergencyReport;
import com.css.fxfzxczh.modules.samplingPointDataCensus.emergencystatistics.entity.EmergencyPoint;
import com.css.fxfzxczh.modules.samplingPointDataCensus.emergencystatistics.entity.EmergencyProportion;
import com.css.fxfzxczh.modules.samplingPointDataCensus.emergencystatistics.repository.EmergencyReportStatisticsRepository;
import com.css.fxfzxczh.modules.samplingPointDataCensus.emergencystatistics.service.EmergencyReportStatisticsService;
import com.css.fxfzxczh.util.PlatformObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/02/21
 * @Description: 灾情急报统计
 */
@Service
public class EmergencyReportStatisticsServiceImpl implements EmergencyReportStatisticsService {
    @Resource
    private EmergencyReportStatisticsRepository emergencyReportStatisticsRepository;


    /**
     * 根据类型获取所有灾情类型分布
     * @param type
     * @return
     */
    @Override
    public List<EmergencyReport> queryAll(String type , String xsemId) {
        return emergencyReportStatisticsRepository.queryAll(type,xsemId);
    }

    /**
     * 灾情类型占比
     * @return
     */
    @Override
    public EmergencyProportion getProportion(String xsemId) {
        //获取伤亡、埋压/被困
        EmergencyProportion obj = emergencyReportStatisticsRepository.getCasualtyStatistically(xsemId);
        Map<String,Object> map=new HashMap<>();
        List<String> xList=new ArrayList<>();
        xList.add(obj.getCasualty());
        xList.add(obj.getPeopleTrapped());
        List<String> yList=new ArrayList<>();
        yList.add("伤亡人数");
        yList.add("埋压/被困人数");
        map.put("x",xList);
        map.put("y",yList);

        obj.setCasualties(map);

        //房屋倒塌
        List<Map<String,Object>> fwList=new ArrayList<>();
        List<String> houseCollapse = emergencyReportStatisticsRepository.getHouseCollapse(xsemId);
        Map fwMap1 = new HashMap<>();//大量
        Map fwMap2 = new HashMap<>();//少量
        Map fwMap3 = new HashMap<>();//个别
        fwMap1.put("name","大量");
        fwMap2.put("name","少量");
        fwMap3.put("name","个别");
        fwMap1.put("value",houseCollapse.get(0));
        fwMap2.put("value",houseCollapse.get(1));
        fwMap3.put("value",houseCollapse.get(2));
        fwList.add(fwMap1);
        fwList.add(fwMap2);
        fwList.add(fwMap3);

        //崩塌
        List<Map<String,Object>> btList=new ArrayList<>();
        List<String> collapse = emergencyReportStatisticsRepository.getCollapse(xsemId);
        Map btMap1 = new HashMap<>();//大规模
        Map btMap2 = new HashMap<>();//中等规模
        Map btMap3 = new HashMap<>();//小规模
        btMap1.put("name","大规模");
        btMap2.put("name","中等规模");
        btMap3.put("name","小规模");
        btMap1.put("value",collapse.get(0));
        btMap2.put("value",collapse.get(1));
        btMap3.put("value",collapse.get(2));
        btList.add(btMap1);
        btList.add(btMap2);
        btList.add(btMap3);

        //滑坡
        List<Map<String,Object>> hpList=new ArrayList<>();
        List<String> landslide = emergencyReportStatisticsRepository.getLandslide(xsemId);
        Map hpMap1 = new HashMap<>();//大规模
        Map hpMap2 = new HashMap<>();//中等规模
        Map hpMap3 = new HashMap<>();//小规模
        hpMap1.put("name","大规模");
        hpMap2.put("name","中等规模");
        hpMap3.put("name","小规模");
        hpMap1.put("value",landslide.get(0));
        hpMap2.put("value",landslide.get(1));
        hpMap3.put("value",landslide.get(2));
        hpList.add(hpMap1);
        hpList.add(hpMap2);
        hpList.add(hpMap3);

        //道路
        List<Map<String,Object>> dlList=new ArrayList<>();
        List<String> road = emergencyReportStatisticsRepository.getLandslide(xsemId);
        Map dlMap1 = new HashMap<>();//完全中断
        Map dlMap2 = new HashMap<>();//严重拥堵
        Map dlMap3 = new HashMap<>();//交通不畅
        dlMap1.put("name","完全中断");
        dlMap2.put("name","严重拥堵");
        dlMap3.put("name","交通不畅");
        dlMap1.put("value",road.get(0));
        dlMap2.put("value",road.get(1));
        dlMap3.put("value",road.get(2));
        dlList.add(dlMap1);
        dlList.add(dlMap2);
        dlList.add(dlMap3);

        //火灾
        List<Map<String,Object>> hzList=new ArrayList<>();
        List<String> fire = emergencyReportStatisticsRepository.getFire(xsemId);
        Map hzMap1 = new HashMap<>();//大规模
        Map hzMap2 = new HashMap<>();//中等规模
        Map hzMap3 = new HashMap<>();//小规模
        hzMap1.put("name","大规模");
        hzMap2.put("name","中等规模");
        hzMap3.put("name","小规模");
        hzMap1.put("value",fire.get(0));
        hzMap2.put("value",fire.get(1));
        hzMap3.put("value",fire.get(2));
        hzList.add(hzMap1);
        hzList.add(hzMap2);
        hzList.add(hzMap3);

        //危险品泄露
        List<Map<String,Object>> dangerousGoodsList=new ArrayList<>();
        List<String> dangerousGoods = emergencyReportStatisticsRepository.getDangerousGoods(xsemId);
        Map dangerousGoods1 = new HashMap<>();//大规模
        Map dangerousGoods2 = new HashMap<>();//中等规模
        Map dangerousGoods3 = new HashMap<>();//小规模
        dangerousGoods1.put("name","大规模");
        dangerousGoods2.put("name","中等规模");
        dangerousGoods3.put("name","小规模");
        dangerousGoods1.put("value",dangerousGoods.get(0));
        dangerousGoods2.put("value",dangerousGoods.get(1));
        dangerousGoods3.put("value",dangerousGoods.get(2));
        dangerousGoodsList.add(dangerousGoods1);
        dangerousGoodsList.add(dangerousGoods2);
        dangerousGoodsList.add(dangerousGoods3);

        //其他
        List<Map<String,Object>> otherList=new ArrayList<>();
        List<String> other = emergencyReportStatisticsRepository.getOther(xsemId);
        Map other1 = new HashMap<>();//大规模
        Map other2 = new HashMap<>();//中等规模
        Map other3 = new HashMap<>();//小规模
        other1.put("name","大规模");
        other2.put("name","中等规模");
        other3.put("name","小规模");
        other1.put("value",other.get(0));
        other2.put("value",other.get(1));
        other3.put("value",other.get(2));
        otherList.add(other1);
        otherList.add(other2);
        otherList.add(other3);
        //返回
        obj.setHouseCollapse(fwList);
        obj.setCollapse(btList);
        obj.setLandslide(hpList);
        obj.setRoad(dlList);
        obj.setFire(hzList);
        obj.setDangerousGoodsList(dangerousGoodsList);
        obj.setOtherList(otherList);
        return obj;
    }
}
